<?php
defined('IN_TS') or die('Access Denied.');

$taskid = intval($_GET['id']);

//任务信息
$strTask = $new['task']->find('task',array(
	'taskid'=>$taskid,
));

if($strTask==''){
	header ( "HTTP/1.1 404 Not Found" );
	header ( "Status: 404 Not Found" );
	$title = '404';
	include pubTemplate ( "404" );
	exit ();
}


if($strTask['isaudit']==1 && $TS_USER['isadmin']==0 || $strTask['isaudit']==1 && $strTask['userid']!=$TS_USER['userid'] && $TS_USER['isadmin']==0){
	tsNotice('任务审核中...');
}

$strTask['title'] = tsTitle($strTask['title']);
$strTask['address'] = tsTitle($strTask['address']);
$strTask['content'] = tsDecode($strTask['content']);
$strTask['coordinate'] = tsTitle($strTask['coordinate']);

$strTask['user'] = aac('user')->getOneUser($strTask['userid']);
$strTask['group'] = aac('group')->getOneGroup($strTask['groupid']);
$strTask['type'] = $new['task']->find('task_type',array(
	
	'typeid'=>$strTask['typeid'],

));

$cover =tsXimg($strTask['photo'],'task',500,'',$strTask['path']);
// 是否点赞

$isRecommend = $new['task']->findCount ( 'task_recommend', array (
	'taskid' => $taskid,
	'userid' => $userid
) );


//taskdo
$isTaskUser = 0;
if($TS_USER['userid']){
	
	$userid = $TS_USER['userid'];
	
	$isTaskUser = $new['task']->findCount('task_users',array(
	
		'taskid'=>$strTask['taskid'],
		'userid'=>$userid,
	
	));

	$isTaskGeter =  $new['task']->findCount('task_users',array(

		'taskid'=>$strTask['taskid'],
		'userid'=>$userid,
		'status'=>1

	));


	if($isTaskUser){
		$strTaskUser = $new['task']->find('task_users',array(

			'taskid'=>$strTask['taskid'],
			'userid'=>$userid,

		));
	}
	
}
$arrGroup = $new['task']->findAll('group','isplace=2','groupid asc');

//认领这个任务的成员
$arrDoUsers = $new['task']->findAll('task_users',array(
	'taskid'=>$strTask['taskid'],
),'addtime desc');

foreach($arrDoUsers as $key=>$item){
	$arrDoUser[] = $item;
	if(aac('user')->isUser($item['userid'])){
		$arrDoUser[$key]['user'] = aac('user')->getOneUser($item['userid']);
	}
}


//完成这个任务的人
$arrTaskUsers = $new['task']->findAll('task_users',array(
	'taskid'=>$strTask['taskid'],
	'status'=>1,
),'addtime desc');

foreach($arrTaskUsers as $item){
	if(aac('user')->isUser($item['userid'])){
		$arrTaskUser[] = aac('user')->getOneUser($item['userid']);
	}
}


//评论

$page = isset($_GET['page']) ? intval($_GET['page']) : 1;

$url = tsUrl('task','show',array('id'=>$taskid,'page'=>''));

$lstart = $page*10-10;

$arrComments = $new['task']->findAll('task_comment',array(
	'taskid'=>$strTask['taskid'],
),'addtime desc',null,$lstart.',10');

foreach($arrComments as $key=>$item){
	if(aac('user')->isUser($item['userid'])){
		$arrComment[$key] = $item;
		$arrComment[$key]['content'] = tsDecode($item['content']);
		$arrComment[$key]['user'] = aac('user')->getOneUser($item['userid']);
	}
}

$commentNum = $new['task']->findCount('task_comment',array(
	'taskid'=>$strTask['taskid'],
));

$pageUrl = pagination($commentNum, 10, $page, $url);

$title = $strTask['title'];
include template("show");